home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / AppsToGo / Kibitz / Init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  5.8 KB  |  168 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:            init.c
  5. ** Some code from:  Traffic Light 2.0 (2.0 version by Keith Rollin)
  6. ** Modified by:     Eric Soldan
  7. **
  8. ** Copyright © 1989-1992 Apple Computer, Inc.
  9. ** All rights reserved. */
  10.  
  11.  
  12.  
  13. /*****************************************************************************/
  14.  
  15.  
  16.  
  17. #include "Kibitz.h"                /* Get the Kibitz includes/typedefs, etc.    */
  18. #include "KibitzCommon.h"        /* Get the stuff in common with rez.        */
  19. #include "Kibitz.protos"        /* Get the prototypes for Kibitz.            */
  20.  
  21. #ifndef __ERRORS__
  22. #include <Errors.h>
  23. #endif
  24.  
  25. #ifndef __GESTALTEQU__
  26. #include <GestaltEqu.h>
  27. #endif
  28.  
  29. #ifndef __UTILITIES__
  30. #include <Utilities.h>
  31. #endif
  32.  
  33.  
  34.  
  35. /*****************************************************************************/
  36.  
  37.  
  38.  
  39. /* Set up the whole world, including global variables, Toolbox managers, and
  40. ** menus.  We also create our one application window at this time.  Since
  41. ** window storage is non-relocateable, how and when to allocate space for
  42. ** windows is very important so that heap fragmentation does not occur. */
  43.  
  44. /* The code that used to be part of ForceEnvirons has been moved into this
  45. ** module.  If an error is detected, instead of merely doing an ExitToShell,
  46. ** which leaves the user without much to go on, we call DeathAlert, which puts
  47. ** up a simple alert that just says an error occurred and then calls
  48. ** ExitToShell.  Since there is no other cleanup needed at this point if an
  49. ** error is detected, this form of error-handling is acceptable.  If more
  50. ** sophisticated error recovery is needed, an exception mechanism, such as is
  51. ** provided by Signals, can be used. */
  52.  
  53.  
  54.  
  55. /*****************************************************************************/
  56.  
  57.  
  58.  
  59. /* NOTE:  The “g” prefix is used to emphasize that a variable is global. */
  60.  
  61. Boolean    gQuitApplication;        /* Set to 0 by Initialize. */
  62.                                 /* Checked by EventLoop. */
  63.  
  64. extern Boolean        gHasAppleEvents;
  65. extern RgnHandle    gCurrentCursorRgn;
  66.  
  67.  
  68. /*****************************************************************************/
  69. /*****************************************************************************/
  70.  
  71. #ifdef applec
  72. #pragma segment Init
  73. #endif
  74.  
  75. /*****************************************************************************/
  76. /*****************************************************************************/
  77.  
  78.  
  79.  
  80. void    Initialize(void)
  81. {
  82.     long        total, contig;
  83.  
  84.     StandardInitialization(1);            /* 1 MoreMasters. */
  85.  
  86.     /* Make sure that the machine has at least 128K ROMs.
  87.     ** If it doesn’t, exit. */
  88.     
  89.     if (gSystemVersion < 0x0700) DeathAlert(rBadNewsStrings, sWimpyMachine);
  90.     
  91.     /* We used to make a check for memory at this point by examining
  92.     ** ApplLimit, ApplicZone, and StackSpace and comparing that to the minimum
  93.     ** size we told MultiFinder we needed.  This did not work well because it
  94.     ** assumed too much about the relationship between what we asked
  95.     ** MultiFinder for and what we would actually get back, as well as how to
  96.     ** measure it.  Instead, we will use an alternate method comprised of
  97.     ** two steps. */
  98.      
  99.     /* It is better to first check the size of the application heap against a
  100.     ** value that you have determined is the smallest heap the application can
  101.     ** reasonably work in.  This number should be derived by examining the
  102.     ** size of the heap that is actually provided by MultiFinder when the
  103.     ** minimum size requested is used.  The derivation of the minimum size
  104.     ** requested from MultiFinder is described in Kibitz.h.  The check should
  105.     ** be made because the preferred size can end up being set smaller than
  106.     ** the minimum size by the user.  This extra check acts to ensure that
  107.     ** your application is starting from a solid memory foundation. */
  108.      
  109.     if ((long) GetApplLimit() - (long) ApplicationZone() < kMinHeap)
  110.         DeathAlert(rBadNewsStrings, sHeapTooSmall);
  111.  
  112.     /* Next, make sure that enough memory is free for your application to run.
  113.     ** It is possible for a situation to arise where the heap may have been of
  114.     ** required size, but a large scrap was loaded which left too little
  115.     ** memory.  To check for this, call PurgeSpace and compare the result with
  116.     ** a value that you have determined is the minimum amount of free memory
  117.     ** your application needs at initialization.  This number can be derived
  118.     ** several different ways.  One way that is fairly straightforward is to
  119.     ** run the application in the minimum size configuration as described
  120.     ** previously.  Call PurgeSpace at initialization and examine the value
  121.     ** returned.  However, you should make sure that this result is not being
  122.     ** modified by the scrap’s presence.  You can do that by calling ZeroScrap
  123.     ** before calling PurgeSpace.  Make sure to remove that call before
  124.     ** shipping, though. */
  125.     
  126.     /* ZeroScrap(); */
  127.  
  128.     PurgeSpace(&total, &contig);
  129.     if (total < kMinSpace)
  130.         DeathAlert(rBadNewsStrings, sNoFreeRoomInHeap);
  131.  
  132.     /* The extra benefit to waiting until after the Toolbox Managers have been
  133.     ** initialized to check memory is that we can now give the user an alert
  134.     ** to tell him/her what happened.  Although it is possible that the memory
  135.     ** situation could be worsened by displaying an alert, MultiFinder would
  136.     ** gracefully exit the application with an informative alert if memory
  137.     ** became critical.  Here we are acting more in a preventative manner to
  138.     ** avoid future disaster from low-memory problems. */
  139.  
  140.     StandardMenuSetup(rMenuBar, mApple);
  141.     AdjustMenus();
  142.  
  143.     InitAppleEvents();
  144.     InitCustomAppleEvents();
  145.  
  146.     if (InitOffscreen()) DeathAlert(rBadNewsStrings, sHeapTooSmall);
  147.     if (InitLogic())     DeathAlert(rBadNewsStrings, sHeapTooSmall);
  148.  
  149.     gCurrentCursorRgn  = NewRgn();        /* The current cursor region. */
  150.     DoSetCursor(&qd.arrow);
  151.  
  152.     qd.randSeed = TickCount();
  153.     gQuitApplication = false;    /* We are only starting.  Don't quit now! */
  154. }
  155.  
  156.  
  157.  
  158. /*****************************************************************************/
  159.  
  160.  
  161.  
  162. void    StartDocuments(void)
  163. {
  164. }
  165.  
  166.  
  167.  
  168.